﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Battleship
{
    public partial class Ship : Form
    {
        public Ship()
        {
            InitializeComponent();

            onClickEvent += new EventHandler(onClick);

            //Region region1 = new Region(new Size(5, 4), 40, onClickEvent, "A");
            //this.Controls.Add(region1);

            //Region region2 = new Region(new Size(5, 4), 40, onClickEvent, "B");
            //region2.Location = new Point(0, region1.Height + 10);
            //this.Controls.Add(region2);

            //this.Height = region1.Height * 2 + 100;
        }

        private void onClick(object sender, EventArgs e)
        {
            Button button = sender as Button;

            if (selectedButton == null)
            {
                selectedButton = button;
                selectedButton.BackColor = Color.RoyalBlue;
            }
            else
            {
                if (selectedButton != button)
                {
                    String tmpString = selectedButton.Text;
                    selectedButton.Text = button.Text;
                    button.Text = tmpString;
                }

                selectedButton.BackColor = Control.DefaultBackColor;
                selectedButton = null;
            }

        }

        private Button selectedButton = null;

        private EventHandler onClickEvent ;
    }
}
